/**
 * Copyright 2011 Joao Miguel Pereira
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package eu.jpereira.trainings.designpatterns.creational.factorymethod;

import java.util.HashMap;
import java.util.Map;

/**
 * The Report Generator will create reports based on a given type
 * 
 * @author jpereira
 * 
 */
public class ReportGenerator
{
    private final Map<String, Class<? extends AbstractReport>> reports;

    public ReportGenerator()
    {
        this.reports = new HashMap<String, Class<? extends AbstractReport>>();
    }

    /**
     * Generate a new report.
     * 
     * @param data
     *            The report data
     * @param type
     *            the type of report
     * @return the generated report, or null of type is unknown
     * @throws IllegalAccessException
     * @throws InstantiationException
     */
    public Report generateReport(ReportData data, String type)
            throws InstantiationException, IllegalAccessException
    {
        Report generatedReport = null;
        Class reportClass = this.reports.get(type);
        if (reportClass == null)
        {
            return null;
        }

        generatedReport = (Report) reportClass.newInstance();
        generatedReport.generateReport(data);
        return generatedReport;
    }

    public void registerReport(String name, Class<? extends AbstractReport> cls)
    {
        this.reports.put(name, cls);
    }

    public static void main(String[] args)
    {
        System.out.println("Yo");
    }
}
